package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo6 {
    public static void main(String[] args) {
        try (
                Connection connection = DBUtil.getConnection();
        ){
            /*
              SELECT count(b.id) as '人数'
              FROM student b, class a
              WHERE a.id = b.class_id
              AND a.name = '1年级2班'
             */
            Statement statement = connection.createStatement();
            String sql = "SELECT count(b.id) as '人数' "+
                         "FROM student b, class a "+
                         "WHERE a.id = b.class_id "+
                         "AND a.name = '1年级2班'";
            ResultSet rs = statement.executeQuery(sql);
            while(rs.next()){
                int count = rs.getInt("人数");
                System.out.println("人数:"+count);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
